import copy
import os

from dataTemp.action import Action
from dataTemp.task import Task

tasks: {str, Task} = {}


def addTask(task: Task):
    tasks[task.name] = task


# copy.deepcopy(tasks[name])
def getTask(name: str) -> Task:
    return tasks[name]


actions: {str, Action} = {}


def addAction(action: Action):
    actions[action.name] = action


def getAction(name: str) -> Action:
    return copy.deepcopy(actions[name])


def initAction(action_path: str):
    for entry in os.listdir(action_path):
        full_path = os.path.join(action_path, entry)
        action = Action(entry)
        action.add_step(full_path)
        # logo.Mlog.logger.debug(full_path)
        # logo.Mlog.logger.debug(action.name)
        # logo.Mlog.logger.debug(len(action.steps))
        addAction(action)

        # folders.append(full_path)


# def create_task(task_path: str):
#     # 遍历当前文件夹下的所有项目
#     for entry in os.listdir(task_path):
#         full_path = os.path.join(task_path, entry)
#         # if os.path.isdir(full_path):
#         task = Task()
#         # logo.Mlog.debug(full_path)
#         task.add_action(full_path)
#         addTask(task)
#         # folders.append(full_path)
#         # elif os.path.isfile(full_path):
#         # files.append(full_path)


if __name__ == "__main__":
    initAction("..\\tasks\\actions")

    # print(actions)
